beginoutdoorscript;

variables;
short choice = 0;
short pc_cycle = 0;

body;

beginstate 0; //INIT_STATE
	
	//If Hektos is destroyed...
	if(get_flag(0,25) == 4) {
		set_floor(17,25,89);
		set_terrain(17,25,483);
		set_terrain(17,24,479);
		set_terrain(17,26,480);
		set_terrain(18,25,479);
		set_terrain(18,26,481);
		set_terrain(16,26,481);
		set_terrain(18,24,482);
		set_terrain(16,24,484);
		set_terrain(16,25,138);
	}

	//If you know where the rebels are
	if(get_flag(1,13) >= 1) {
		set_terrain(28,3,339);
		set_terrain(29,3,146);
		set_terrain(29,4,145);
	}

	//If you've cleared path to spiders
	if(get_flag(20,2) == 1) {
		set_terrain(32,24,0);
		set_terrain(32,24,0);
	}

break;

beginstate 1; //EXIT_STATE

break;

beginstate 2; //START_STATE
	
	//If Hektos is destroyed...
	if(get_flag(0,25) == 4) {
		set_floor(17,25,89);
		set_terrain(17,25,483);
		set_terrain(17,24,479);
		set_terrain(17,26,480);
		set_terrain(18,25,479);
		set_terrain(18,26,481);
		set_terrain(16,26,481);
		set_terrain(18,24,482);
		set_terrain(16,24,484);
		set_terrain(16,25,138);
	}

	//If you know where the rebels are
	if(get_flag(1,13) >= 1) {
		set_terrain(28,3,339);
		set_terrain(29,3,146);
		set_terrain(29,4,145);
	}

	//If you've cleared path to spiders
	if(get_flag(20,2) == 1) {
		set_terrain(32,24,0);
		set_terrain(32,24,0);
	}


break;

beginstate 5; //leave scenario (south)
	block_entry(1);
	reset_dialog();
	add_dialog_str(0, "Walking towards the edge of the province, you approach a simply immense forest, one which stretches easily to the horizons.",0);
	add_dialog_str(1, "If you followed this road, you would eventually reach Blackcrag Fortress, and you'd be able to catch a caravan to the coast. After that, the possibilities are endless.",0);
	add_dialog_str(2, "Do you wish to leave the scenario?", 0);
	add_dialog_choice(0, "No. I wish to continue exploring Yris.");
	add_dialog_choice(1, "Yes, I've got better things to do.");
	choice = run_dialog(1);
	if(choice == 2) {
		reset_dialog();
		add_dialog_str(0,"You set off for Blackcrag Fortress, confident in your choice to leave this all behind you. However, you can't help but reflect on what you've accomplished.",0);
		set_state_continue(7);
		}
break;



beginstate 6; //leave scenario (west, NE)
	block_entry(1);
	reset_dialog();
	add_dialog_str(0, "This road clearly leads up into the mountains, which would take you out of Yris. While you can't be certain what lies along this road, it would certainly be a change of pace.",0);
	add_dialog_str(1, "Do you wish to leave the scenario?", 0);
	add_dialog_choice(0, "No. I wish to continue exploring Yris.");
	add_dialog_choice(1, "Yes, I've got better things to do.");
	choice = run_dialog(1);
	if(choice == 2) {
		reset_dialog();
		add_dialog_str(0,"You head up into the mountains, confident in your choice to leave this all behind you. However, you can't help but reflect on what you've accomplished.",0);
		set_state_continue(7);
		}
break;


beginstate 7; //actually leaving scenario

	if(get_flag(3,4) == 0) {
		add_dialog_str(1,"Actually, seeing as you never even delivered the package you were sent here with, you basically accomplished nothing. Congratulations.",0);
		}
	else {
		add_dialog_str(1,"You delivered your package, and witnessed the fiery destruction of Hektos. You're fairly certain that you'll never get that image out of your mind.",0);
		if((get_flag(4,19) >= 2) || (get_flag(4,20) >= 4) || (get_flag(4,21) > 0))
			add_dialog_str(2,"You'll be able to sleep better, though, after doing your level best to help the people of Hektos recover from their tragedy.",0);	
		else
			add_dialog_str(2,"Of course, the fact that you didn't lift a finger to help the townspeople recover won't help you sleep any better.",0);
		if(get_flag(5,8) != 2)
			add_dialog_str(3,"Then again, the worst part of leaving now is that you'll probably never know who exactly blew up Hektos, and what their next move was to be.",0);
		else
			add_dialog_str(3,"Then again, the worst part of leaving now is that you know who blew up Hektos, and that you just let them go.",0);
		add_dialog_str(4,"All of that aside, you're grateful to leave this all behind you, and you're certain that you can find somewhere more peaceful out there.",0);
		}

	run_dialog(1);
	end_scenario(0);

break;


beginstate 10; //cows
	outdoor_enc_result(1);
	message_dialog("Some farmer has left their cows out here to graze. Predictably, they moo at you.", "They don't do anything else, so you leave them alone.");
break;

beginstate 11; //farmers

	if(get_flag(0,25) != 4)
		message_dialog("The farmers here seem rather friendly, and you chat with them for a while about nothing in particular. You don't learn anything new, but it's quite relaxing.","They don't have anything to sell you, because the harvests haven't happened quite yet.");
	else {
		if(get_flag(4,19) == 1)
			message_dialog("The farmers here seem rather nervous, and refuse to talk to you. They're probably just on edge after the blasts.","When you tell them about the need for food in Hektos, they just say they're sorry, and that the harvests haven't come in yet.");
		else
			message_dialog("The farmers here seem rather nervous, and refuse to talk to you. They're probably just on edge after the blasts.","They don't have anything to sell you, because the harvests haven't happened quite yet.");
		}

break;

beginstate 15; //after cutscene, running into Stirlen

//If Stirlen got transferred, or if you didn't send him over edge, no cutscene
if(get_flag(2,16) == 2)
	end();

if((get_flag(20,0) == 0) && (get_flag(0,25) == 4)) {
	reset_dialog();
	add_dialog_str(0,"As you head back towards the ruins of Hektos, you hear rushed footsteps on the road behind you. When you turn around to look, you see a young soldier dashing towards you at full speed.",0);
	add_dialog_str(1,"Normally, you'd consider drawing weapons, but the man bolts past you at top speed before you can do anything. You barely get a glimpse of his face.",0);
	if(get_flag(2,13) >= 2)
		add_dialog_str(2,"Somehow, you still manage to recognize the man. It was Private Stirlen, the deeply-disturbed man you talked to in Fort Galima. This could have something to do with the woman he mentioned.",0);
	if(get_flag(2,13) == 3)
		add_dialog_str(3,"Come to think of it, with how worked-up he sounded back at the fort, this can't be good. You're not sure you want to know what he plans on doing.",0);
	run_dialog(1);
	set_flag(20,0,1);
}

break;



beginstate 20; //entrance to path to rebels

	if(get_flag(1,13) == 1) {
		reset_dialog();
		add_dialog_str(0,"This is interesting. You probably never would've noticed this path had Private Scott not told you about it, but now it's rather obvious.",0);
		add_dialog_str(1,"The forest is definitely thinner here, and there's a clear path up to the cliffs by the waterfall. Footprints are clearly visible in patches of dried mud.",0);
		add_dialog_str(2,"Whoever these rebels are, they don't seem to care much about being found.",0);
		run_dialog(1);
		set_flag(1,13,2);
	}

break;



beginstate 30;

	reset_dialog();
	if(get_flag(20,1) == 0) {
		add_dialog_str(0,"Where the bottom of this hill meets the lake, there's an empty-looking shack and a smoldering campfire. It's very, very quiet down here.",0);
		add_dialog_str(1,"Cautiously, you approach the building, and prepare to break down the door, like any good adventurer would. But before you get the chance, a slight gust of wind does the work for you.",0);
		add_dialog_str(2,"The shack is basically empty. You leave, disappointed in the lack of treasure.",0);
		}
	else
		add_dialog_str(0,"The building is still empty, and there's still nobody around.",0);
	run_dialog(1);
	block_entry(1);

break;


beginstate 35; //path to spiders

	if(get_flag(20,2) == 0) {
	
	reset_dialog();
	add_dialog_str(0,"The path you've been following seems to disappear here, running into a particularly solid stand of trees.",0);

	if(get_skill_total(16) >= 6) {
		add_dialog_str(1,"However, with your Nature Lore skill, you're able to locate the path again, even though it's incredibly faint.",0);
		set_terrain(32,24,0);
		set_terrain(32,25,0);
		set_flag(20,2,1);
	}
	run_dialog(1);

	}
break;


beginstate 40; //The spiders

	reset_dialog();
	add_dialog_str(0,"There's a large group of aranea in this clearing. Normally, your first reaction would be to take cover and prepare for a long, drawn-out fight, but the spiders don't move to attack.",0);
	add_dialog_str(1,"They're so quiet that it's eerie. So quiet, in fact, that you don't notice when a few sneak around behind you, blocking your way out of the clearing. But they still show no signs of attacking.",0);
	add_dialog_str(2,"You're just not sure what to do.",0);
	add_dialog_choice(0,"Attack!");
	add_dialog_choice(1,"Wait.");
	choice = run_dialog(1);

	if(choice == 2) {
		reset_dialog();
		add_dialog_str(0,"For a while, you just stare at the aranea, and they stare right back. Finally, one of them moves towards you.",0);
		add_dialog_str(1,"You draw weapons, just in case. This makes the aranea scuttle back. However, once they seem to have realized that you're not attacking yet, the one approaches again.",0);
		add_dialog_str(2,"This particular aranea seems to be an elder. At least, that's what you'd guess from the graying exoskeleton. It also seems to be limping... or rather, something's wrong with one leg.",0);
		add_dialog_str(3,"The elder aranea points at its injured leg with two of its other legs, and lowers its body until it's flat on the ground. It's almost as if it wants your help.",0);
		add_dialog_choice(0,"It's just a trick. Attack!");
		if((get_skill_total(12) > 0) || ((get_skill_total(17) >= 6) && ((has_item(177) == 1) || (has_item(178) == 1))))
			add_dialog_choice(1,"Try to help the injured aranea.");
		choice = run_dialog(1);
		if(choice == 2) {
			reset_dialog();
			if(get_skill_total(12) > 0)
				add_dialog_str(0,"Not quite sure where to begin, you try casting a basic healing spell on the elder aranea. The injured leg glows a faint blue for a moment, then returns to its former grayish-purple hue.",0);
			else
				add_dialog_str(1,"Not quite sure where to begin, you pull out a first aid kit and try to splint the aranea's leg. It shudders when you first touch its leg, but it stays calm long enough for you to splint it.",0);
			add_dialog_str(1,"Then, you carefully step away from the elder aranea in what you sincerely hope is a respectful manner, and wait.",0);
			add_dialog_str(2,"The elder slowly stands up, as much as a giant spider can, anyway, and shuffles its feet around a bit. The movements seem a bit more sure than before, and they're certainly less painful to watch.",0);
			add_dialog_str(3,"You're still waiting for some sort of resolution when the elder raises one leg in the air, and the entire group suddenly leaves the clearing, not really paying you any attention.",0);
			run_dialog(1);

			award_party_xp(50,10);
			outdoor_enc_result(3);
			set_flag(1,12,3);
			}
		else
			set_out_fight_town_loaded(9);
		}
	else
		set_out_fight_town_loaded(9);

break;



beginstate 41; //Beating the spiders

	reset_dialog();
	add_dialog_str(0,"When the last aranea falls, you look around anxiously to see if more are on their way. Fortunately, the clearing stays quiet, and you sheathe your blades with a sigh of relief.",0);
	run_dialog(1);
	set_flag(1,12,2);

break;



beginstate 45; //picking herbs

	if(get_flag(20,3) == 0) {
		reset_dialog();
		add_dialog_str(0,"In the corner of this clearing, you find a rather impressive patch of herbs.",0);
		if(get_skill_total(16) >= 10) {
			add_dialog_str(1,"Thanks to your Nature Lore skill, you can identify some of them. You see mandrake, wolfsbane, and a few comfrey plants, and a few young ember flower plants.",0);
			add_dialog_str(2,"Regrettably, the ember flowers appear to be too young to pick. They'd fetch an impressive price in any alchemical market.",0);
			}
		add_dialog_str(3,"Do you collect some herbs?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");
		choice = run_dialog(1);

		if(choice == 2)
			end();
		else {
			if(get_skill_total(16) >= 10) {
				message_dialog("You harvest some of each herb, making sure to leave enough for the plants to recover.","");
				reward_give(214);
				reward_give(214);
				reward_give(214);
				reward_give(216);
				reward_give(216);
				reward_give(219);
				}
			else {
				message_dialog("You don't know enough about herbs to really identify much of these... but you do stumble across a few comfrey plants.","You dig up the roots and throw them in with the rest of your equipment.");
				reward_give(214);
				reward_give(214);
				}
			set_flag(20,3,1);
			}
		}

	else {
		message_dialog("This patch of herbs is still recovering from the last time you picked some... there's not really enough left to collect any more.","");
		}

break;